package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yanjing.domain.SafetyScenario;
import com.ruoyi.yanjing.service.ISafetyScenarioService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安全生产场景Controller
 * 
 * @author whz
 * @date 2024-12-06
 */
@RestController
@RequestMapping("/yanjing/scenario")
public class SafetyScenarioController extends BaseController
{
    @Autowired
    private ISafetyScenarioService safetyScenarioService;

    /**
     * 查询安全生产场景列表
     */
    @PreAuthorize("@ss.hasPermi('yanjing:scenario:list')")
    @GetMapping("/list")
    public TableDataInfo list(SafetyScenario safetyScenario)
    {
        startPage();
        List<SafetyScenario> list = safetyScenarioService.selectSafetyScenarioList(safetyScenario);
        return getDataTable(list);
    }

    /**
     * 导出安全生产场景列表
     */
    @PreAuthorize("@ss.hasPermi('yanjing:scenario:export')")
    @Log(title = "安全生产场景", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafetyScenario safetyScenario)
    {
        List<SafetyScenario> list = safetyScenarioService.selectSafetyScenarioList(safetyScenario);
        ExcelUtil<SafetyScenario> util = new ExcelUtil<SafetyScenario>(SafetyScenario.class);
        util.exportExcel(response, list, "安全生产场景数据");
    }

    /**
     * 获取安全生产场景详细信息
     */
    @PreAuthorize("@ss.hasPermi('yanjing:scenario:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(safetyScenarioService.selectSafetyScenarioById(id));
    }

    /**
     * 新增安全生产场景
     */
    @PreAuthorize("@ss.hasPermi('yanjing:scenario:add')")
    @Log(title = "安全生产场景", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SafetyScenario safetyScenario)
    {
        return toAjax(safetyScenarioService.insertSafetyScenario(safetyScenario));
    }

    /**
     * 修改安全生产场景
     */
    @PreAuthorize("@ss.hasPermi('yanjing:scenario:edit')")
    @Log(title = "安全生产场景", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SafetyScenario safetyScenario)
    {
        return toAjax(safetyScenarioService.updateSafetyScenario(safetyScenario));
    }

    /**
     * 删除安全生产场景
     */
    @PreAuthorize("@ss.hasPermi('yanjing:scenario:remove')")
    @Log(title = "安全生产场景", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(safetyScenarioService.deleteSafetyScenarioByIds(ids));
    }
}
